import type { AppRouteRecordRaw, AppRouteModule } from '/#/route';
import { PageEnum } from '/@/enums/pageEnum';
import { LAYOUT } from '/@/router/constant';

const modules = import.meta.globEager('./modules/**/*.ts');

const routeModuleList: AppRouteModule[] = [];

Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  routeModuleList.push(...modList);
});

export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  redirect: PageEnum.BASE_LOGIN,
  meta: {
    title: 'Root',
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('../../views/sys/login/Login.vue'),
  meta: {
    title: '登录',
    // ignoreAuth: true,
  },
};

export const MediaRoute: AppRouteRecordRaw = {
  path: '/media',
  name: 'Media',
  component: () => import('/@/views/sys/media/index.vue'),
  meta: {
    title: '登录跳转页',
    ignoreAuth: true,
  },
};

export const UserInfoRoute: AppRouteRecordRaw = {
  path: '/userInfo',
  name: 'UserInfo',
  component: LAYOUT,
  redirect: '/userInfo',

  children: [
    {
      path: '/userInfo',
      name: 'UserInfo',
      component: () => import('/@/views/sys/userInfo/index.vue'),
      meta: {
        title: '个人信息',
      },
    },
  ],
  meta: {
    title: '个人信息',
    ignoreAuth: true,
  },
};

export const MonoMediaRoute: AppRouteRecordRaw = {
  path: '/monoMedia',
  name: 'MonoMedia',
  component: () => import('/@/views/integrated-center/open-client/index.vue'),
  meta: {
    title: '单体应用登录跳转页',
    ignoreAuth: true,
  },
};

export const LayoutRoot: AppRouteRecordRaw = {
  path: '/layout',
  name: 'Layout',
  component: () => import('/@/layout/default/index.vue'),
  meta: {
    title: 'Layout',
  },
};

// Basic routing without permission
export const basicRoutes = [LoginRoute, RootRoute, MediaRoute, MonoMediaRoute, UserInfoRoute, LayoutRoot];
